package com.yzc.mihuyou.controller;


import com.yzc.mihuyou.entity.Give;
import com.yzc.mihuyou.entity.User;
import com.yzc.mihuyou.mapper.UserMapper;
import com.yzc.mihuyou.service.GiveService;
import com.yzc.mihuyou.service.UserService;
import com.yzc.mihuyou.service.impl.UserServiceImpl;
import com.yzc.mihuyou.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author 易紫诚
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/mihuyou/give")
public class GiveController {

    @Autowired
    GiveService giveService;

    @Autowired
    UserServiceImpl userService;

    @PostMapping("zanwu")
    public JsonResult zanwu(Give give, Integer is){
        giveService.owGive(give,is);
        return  new JsonResult(200,"收藏或点赞成功");
    }

    @GetMapping("themeGood/{id}")
    public JsonResult themeGood(@PathVariable("id") long id){
        List<Give> list =  giveService.themeGood(id);
        for(Give Glist : list){
            Glist.setUser((User) userService.getUser(Glist.getGiveUserid()).getData().get("data"));
        }
        Map map = new HashMap();
        map.put("data",list);
        if(map.size()>0){
            return new JsonResult(200,"查询成功",map);
        }
        return new JsonResult(500,"出现异常",map);
    }


}

